﻿import idv.ben.gc4flash.chart.*;
import idv.ben.gc4flash.dataLine.*;
import idv.ben.gc4flash.encode.*;
import idv.ben.gc4flash.fill.*;
import idv.ben.gc4flash.style.*;
import idv.ben.gc4flash.util.*;
/**
* 長條圖、直方圖。<br>
* 參考 Google Chart API：<a href="http://code.google.com/apis/chart/#bar_charts" target="_blank">http://code.google.com/apis/chart/#bar_charts</a><br>
*/
class idv.ben.gc4flash.chart.BarChart extends AbstractChart {
	private var barStyle:BarStyle;
	/**
	* 水平長條圖<br>
	* <img src="http://chart.apis.google.com/chart?cht=bhs&chs=200x125&chd=s:HELL,WORL&chco=ff0000,00aa00"><br>
	* cht=bhs
	*/
	public static var CHART_TYPE_BarChart_Horizontal1:String = "bhs";
	/**
	* 垂直長條圖<br>
	* <img src="http://chart.apis.google.com/chart?cht=bvs&chs=200x125&chd=s:hello,world&chco=cc0000,00aa00&chbh=20"><br>
	* cht=bvs
	*/
	public static var CHART_TYPE_BarChart_Vertical1:String = "bvs";
	/**
	* 水平群組長條圖<br>
	* <img src="http://chart.apis.google.com/chart?cht=bhg&chs=200x125&chd=s:el,or&chco=cc0000,00aa00"><br>
	* cht=bhg
	*/
	public static var CHART_TYPE_BarChart_Horizontal2:String = "bhg";
	/**
	* 垂直群組長條圖<br>
	* <img src="http://chart.apis.google.com/chart?cht=bvg&chs=200x125&chd=s:hello,world&chco=cc0000,00aa00"><br>
	* cht=bvg
	*/
	public static var CHART_TYPE_BarChart_Vertical2:String = "bvg";
	/**
	* 建構子
	* @param w 圖檔寬度
	* @param h 圖檔高度
	* @param typ 圖形種類，包括：<br>
	* {@link #CHART_TYPE_BarChart_Horizontal1} = "bhs"<br>
	* {@link #CHART_TYPE_BarChart_Vertical1} = "bvs"<br>
	* {@link #CHART_TYPE_BarChart_Horizontal2} = "bhg"<br>
	* {@link #CHART_TYPE_BarChart_Vertical2} = "bvg"<br>
	*/
	function BarChart(w:Number, h:Number, typ:String) {
		super(w, h);
		if (typ == CHART_TYPE_BarChart_Horizontal1 || typ == CHART_TYPE_BarChart_Vertical1 || typ == CHART_TYPE_BarChart_Horizontal2 || typ == CHART_TYPE_BarChart_Vertical2) {
			this.typ = typ;
		} else {
			throw new Error("chart type error!!");
		}
		allowParams = Const.CHT_PARAM_Bar_chart;
	}
	/**
	* 新增一條長條資料
	* @param values 單一長條資料的數值陣列，[n1:Number, n2:Number, ..., nN:Number]
	* @param legend 圖示說明<br>
	* <img src="http://chart.apis.google.com/chart?&cht=lc&chd=t:0,30,60,70,90,95,100|20,30,40,50,60,70,80|10,30,40,45,52&chco=ff0000,00ff00,0000ff&chs=250x150&chdl=First|Second|Third"><br>
	* chdl=First|Second|Third&chco=ff0000,00ff00,0000ff<br>
	*/
	public function addLine(values:Array, legend:String):Void {
		var ds:ChartDataSet = new ChartDataSet();
		for(var i:Number=0; i<values.length; i++){
			ds.addValue(values[i]);
		}
		var dataLine:DataLine = new LegendDataLine([ds], legend);
		lines.push({line:dataLine});
	}
	/**
	* 設定長條圖樣式
	* @param barStyle {@link idv.ben.gc4flash.dataLine.BarStyle}
	**/
	public function setBarStyle(barStyle:BarStyle):Void{
		this.barStyle = barStyle;
	}
	/**
	* 取得長條圖樣式所組成的 URL 參數字串
	* @return URL 參數字串
	**/
	public function getBarStyleChartData():String{
		if(barStyle!=null){
			return "&chbh=" + barStyle.toChartData();
		}else{
			return "";
		}
	}
}
